/* clock.h
 * By: Ariq Chowdhury
 * Date created: March 17th 2011
 * Modified by: Samuel Ferguson
 * Date modified: March 26th 2011
 */

#include <clock.h>
#include <sys/io.h>
#include <interrupt.h>
#include <xxxio.h>

static int_hook_t clock_hook;

/* Intel 8254 */
/* Datasheet: bochs.sourceforge.net/techspec/intel-82c54-timer.pdf.gz */
void init_clock()
{
  outb(SQUARE_WAVE, TIMER_MODE);
  
  outb(TIMER_COUNT & 0x00ff, TIMER0);
  outb((TIMER_COUNT & 0xff00) >> 8, TIMER0);
  set_int_handler(&clock_hook, CLK_INT, clock_handler);
  enable_interrupt(&clock_hook);
}

int clock_handler(int_hook_t* hook)
{
  /* xprintf("Clk"); */
  eoi(CLK_INT);
  return 17; /*Print something out*/
}
